package com.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class Demo03Servlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //doGet请求 中文乱码
        //获取请求参数
        String hobby = req.getParameter("hobby");
        //1.先用iso8859-1进行编码
        //2.再用utf-8进行解码
        hobby = new String(hobby.getBytes("iso-8859-1"),"UTF-8");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //POST请求中文乱码
        req.setCharacterEncoding("UTF-8");
    }
}
